using UnityEngine;

public class UI_Quest : MonoBehaviour
{
    [SerializeField] private UI_ItemSlotParent itemSlotParent;
    private UI_QuestPreview questPreview;
    public PlayerQuestManager questManager { get; private set; }
    private UI_QuestSlot[] questSlots;
    private void Awake()
    {
        questSlots = GetComponentsInChildren<UI_QuestSlot>();
        questPreview = GetComponentInChildren<UI_QuestPreview>();
    }
    public void SetupQuestUI(QuestDataSO[] questsToSetup)
    {
        questManager = Player.Instance.questManager;

        foreach (var slot in questSlots)
            slot.gameObject.SetActive(false);

        for (int i = 0; i < questsToSetup.Length; i++)
        {
            questSlots[i].gameObject.SetActive(true);
            questSlots[i].SetupQuestSlot(questsToSetup[i]);
        }

        itemSlotParent.UpdateSlot(Player.Instance.playerInventory.itemList);

        //如果当前没有接受任何任务，则打开任务面板时默认为第一个任务
        if (questsToSetup.Length != 0)
            if (questManager.GetQuestList().Count == 0 || questPreview.questDataSO == null)
                questPreview.InitQuestPreview(questsToSetup[0]);
    }
    public void UpdateQuestList()
    {
        foreach (var slot in questSlots)
            if (slot.gameObject.activeSelf)
                slot.UpdateSlotBorder();
    }
}
